#!/usr/bin/env python3
# coding:utf-8
import requests
import json
# server_url = 'http://0.0.0.0:8080/core/user/'
# server_url = 'http://0.0.0.0:8080/core/area/'
# server_url = 'http://0.0.0.0:8080/core/button/'
server_url = 'http://0.0.0.0:8080/core/module/'
def test_add_user_interface():
    data = {'id': 2, 'username': "12", 'password':'123456','email': 'rui@163.com'}
    url = server_url + 'add_user'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def test_get_province():
    data = {}
    url = server_url + 'get_province'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def test_add_button():
    data = {'id': 100, 'name': "crui", 'code':'123456a','parent_id': '1',
            'module_id': '1'}
    url = server_url + 'add'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def test_add_module():
    data = {
    'id': 100,
    "name":"lihongzhi",
    "code":"d333444",
    "path":'1',
    "parent_id":2,
    "description":"dddd"
    }
    url = server_url + 'add/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def test_del_module():
    data = {
    'id': 84,
    }
    url = server_url + 'del/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def test_edit_module_interface():
    data = {
    'id': 85,
    "name":"李若彤",
    "code":"301",
    "path":'1333',
    "parent_id":24,
    "description":"美女"
    }
    url = server_url + 'edit/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def test_module_search():
    data = {'query_word': '设备'}
    url = server_url + 'search/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    # r = requests.post(url, params=data, headers=headers)
    # r = requests.post(url=url, data=json.dumps(data))
    print(type(r))
    print(r.json())

# test_add_user_interface()
# test_get_province()
# test_add_button()
test_add_module()
# test_del_module()
# test_edit_module_interface()
# test_module_search()

if __name__ == '__main__':
    pass